package com.lizhe.async.task;

import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.AsyncResult;
import org.springframework.stereotype.Component;

import java.util.concurrent.Future;

/**
 * 类描述: 带回调的异步方法  Future
 *
 * @author Lz on 2021-11-15
 */
@Component
public class AsyncCallBackTask extends AbstractTask {

    //创建 AsyncTask类，分别在方法上配置 @Async 注解，将原来的 同步方法 变为 异步方法。
    public Future<String> doTaskOneCallback() throws InterruptedException {
        super.doTaskOne();
        return new AsyncResult<>("任务一完成");
    }

    @Async
    public Future<String> doTaskTwoCallback() throws InterruptedException {
        super.doTaskTwo();
        return new AsyncResult<>("任务二完成");
    }


    @Async
    public Future<String> doTaskThreeCallback() throws InterruptedException {
        super.doTaskThree();
        return new AsyncResult<>("任务三完成");
    }
}
